﻿Chenxin.UI.TraceManage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: 'service/traceHandler.ashx',
    createGrid: function() {
        // return new Chenxin.UI.Pagination({
            // actionUrl: this.actionUrl + '?op=getlist',
            // domId: 'page',
            // pageSize: 50,
            // renderTo: 'trace_table',
            // data: {},
            // render: function(data) {
                // document.getElementById('trace_table').innerHTML = data;
            // }
        // });
		
		return new Chenxin.UI.ContentGrid({
            actionUrl: this.actionUrl + '?op=getlist',
			pageSize:50,
			id:'trace_grid',
			modelId:'TraceId',
			renderTo:'trace_table',
			contentField:'TraceContext',
			scope:this,
			columns:{
				HouseCode:{
					head:'编号',
					width:160,
					sortable:true,
					renderer:function(val,c,row){
						if(row.status=='0'){						
							return '<a name=\"'+row.HouseId+'\" class=\"a_favor_house\" href=\"ShowDetailInfo.aspx?houseid='+row.HouseId+'\" target=\"blank\">'+val+'</a>';
						}
						return val;
					}
				},
				HouseAddress:{
					head:'地址',
					width:200,
					sortable:true
				},
				TraceTime:{
					head:'跟单时间',
					width:140,
					sortable:true
				},
				Tractor:{
					head:'跟单人',
					width:120,
					renderer:function(val,c,row){
						return val+'/'+row.Depart
					}
				},
				OprPerson:{
					head:'操作人',
					width:120,
					renderer:function(val,c,row){
						return val+'/'+row.OprDepart
					}
				}
			}
		});
		
    },
    addlist: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            url: this.actionUrl,
            data: { op: 'addtracelist', id: _this.currentId },
            onSuccess: function(data, msg) {
                alert(msg);
            }
        });
    },
    cancle: function() {

    },
    initEvent: function() {
        var _this = this;
		
		$('#btn_deltrace').click(function(){
            _this.del();
		});
		
		$('#btn_viewovner').click(function(){
			var houseId=_this.grid.getCurrentField('HouseId');
            _this.showViewOwnerRecorde([houseId,_this.currentId]);	
		});
		$('#btn_addtracelist').click(function(){
            _this.addlist();
            _this.reloadGrid();
		});
		
    },
    showViewOwnerRecorde: function(pa) {
		if(!this.currentId){
			alert('请选择一条记录！');
			return;
		}
        if (!this.voWin) {
            this.voWin = new Chenxin.UI.ViewOwnerWin({
                scope: this,
                title: '查看业主列表',
                op: 'viewownerrecord'
            });
        }
        if (this.voWin.show()) {
            this.voWin.grid.reload({ houseid: pa[0], employeeid: pa[1] });
        }
    },
    createSearch: function() {
        return new Chenxin.UI.TraceManageSearch({
            scope: this
        });
    },
    initComponent: function() {
        Chenxin.UI.TraceManage.superclass.initComponent.call(this);
    }
});

/**
*查询面板
*/
Chenxin.UI.TraceManageSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
	id:'trace_search',
	initEvent:function(){
		var _this=this;
		$('#btn_search').click(function(){
			_this.scope.reloadGrid();
		});
	},
	createComboList:function(){
		var tracetype=new Chenxin.UI.Combo({
				containerId:'#tracetype',
				tbxWidth:40,
				items:comboCommon.traceType
			});
		var combl=new Chenxin.UI.StructComboList();
		var structs = combl.comboList;
		structs.push(tracetype);
		return structs;
	},
	initComponent:function(){
		Chenxin.UI.TraceManageSearch.superclass.initComponent.call(this);
	}
});

Chenxin.UI.ViewOwnerWin=Chenxin.extend(Chenxin.UI.FormCommon,{
	id:'viewownerrecord',
	renderTo:'jqm_vor',
	jqmWidth:700,
	actionUrl:'service/traceHandler.ashx',
	createBBtn:function(){
		return [{
			text:'取消',
			handler:this.hide,
			scope:this
		}]
	},
	createGrid:function(){			
		return new Chenxin.UI.JsonGrid({
			actionUrl:this.actionUrl+'?op=getviewownerlist',
			id:'vor',
			renderTo:'vor_list',
			autoLoad:false,
			pageSize:5,
			height:200,
			hasCheckBox:false,
			columns:{
				HouseCode:{
				head: '房源/客户编号',
				width: 150,
					sortable:true
				},
				HouseAddress:{
				head: '房源地址/客户姓名',
				width: 150,
					sortable:true
				},
				Employee:{
					head:'查看人',
					width:50,
					sortable:true
				},
				Depart:{
					head:'部门',
					width:70,
					sortable:true
				},
				Addtime:{
					head:'查看时间',
					width:120,
					sortable:true
				}
			},
			scope:this
		});
	},
	createForm:function(){
		return Chenxin.FormCommon.communityBaseInfoForm(this.id);
	},
	initEvent:function(){	
		var _this=this;
		$('#'+this.id+'_Cancle').live('click',function(){
			_this.hide();
		});	
	},
	initComponent:function(){
		Chenxin.UI.ViewOwnerWin.superclass.initComponent.call(this);
		this.grid=this.createGrid();
	}
});

/**
*@description 产看业主信息弹出窗
*@method 提交按钮的处理方法
*/
Chenxin.FormCommon.communityBaseInfoForm=function(comboIdPrefix){
        return '<div id="vor_list"></div>';
}


$(document).ready(function(){
	var traceMgr=new Chenxin.UI.TraceManage();	
});





